define(function(require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    // require('commonjs');
    //
    
    
    
    
    
    
    

    $.widget('rk.taskContentCtrl', $.rk.oaContentCtrl, {
        _create: function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            me._initTaskDetail();
        },
        _init: function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;
        },
        _initTaskDetail: function() {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var url = '/json/crm_task/detail.action';
            rk.post(url, {
                taskId: opt.taskId
            }).done(function(json) {
                if (json.status == 0) {
                    json.data.task.description = json.data.task.description;
                    me.data = json.data;
                    me._buildData();
                    me._rendTaskDetail();
                } else if (json.status == 300002) {
                    var html = rk.templateText(require("oa/tmpl/approval/tpl_approval_content_default_detail.tpl"), {
                        noticeError: rk.i18n('TASK_IS_DELETED')
                    });
                    elem.html(html);
                } else if (json.status == 212002) {
                    var html = rk.templateText(require("oa/tmpl/approval/tpl_approval_content_default_detail.tpl"), {
                        noticeError: "您无权查看该任务或已删除"
                    });
                    elem.html(html);
                } else {
                    var html = rk.templateText(require('oa/tmpl/approval/tpl_approval_content_default_detail.tpl'), {
                        noticeError: rk.i18n('LOAD_ERROR')
                    });
                    elem.html(html);
                }
            });
        },
        rMap: {
            1: {
                name: SESSION.keywords.account,
                url: '/final/account.action?id=',
                cname: 'account'
            },
            2: {
                name: SESSION.keywords.contact,
                url: '/final/contact.action?id=',
                cname: 'contact'
            },
            3: {
                name: SESSION.keywords.opportunity,
                url: '/final/opportunity.action?id=',
                cname: 'opportunity'
            },
            6: {
                name: SESSION.keywords.campaign,
                url: '/final/campaign.action?id=',
                cname: 'campaign'
            },
            11: {
                name: SESSION.keywords.lead,
                url: '/final/lead.action?id=',
                cname: 'lead'
            },
            66:{
                name: '代理商',
                url: '/final/agent.action?id=',
                cname: 'terminal'
            },
            67:{
                name: '终端',
                url: '/final/terminal.action?id=',
                cname: 'terminal'
            }
        },
        _buildData: function() {
            var $this = this,
                $elem = this.element,
                opt = this.options;
            var t = $this.data.task;
            var isAdmin = SESSION.user.id == t.createdBy,
                isOwner = SESSION.user.id == t.ownerId,
                isJoiner = $.inArray(SESSION.user.id, $this.data.members) > -1;
            $.extend(t, {
                ownerName: $this.data.users[t.ownerId].name,
                ownerIcon: $this.data.users[t.ownerId].icon || DEFAULTS.USER_DEFAULT_ICON,
                description: $.htmlEncode(t.description).replace(/\n/g, '<br>') || ('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_DESCRIPTION')+'</span>'),
                relObject: t.belongId ? rk.templateText(
                    '<span class="task_group"><p class="feed-group-name"><span title="{{belongName}}" class="feed-group-class {{belongClass}}"></span><a title="{{objectName}}" href="{{objectpage}}" target="_blank" class="">{{objectName}}</a></p></span>', {
                        belongName: $this.rMap[t.belongId].name,
                        belongClass: $this.rMap[t.belongId].cname,
                        objectpage: $this.rMap[t.belongId].url + t.objectId,
                        objectName: $this.data.sourceEntity.name
                    }) : ('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_SET')+'</span>'),
                objectLink: (!t.belongId && (isAdmin || isOwner)) ? ('<a class="edit_link js-belong" title="" href="javascript:;">'+rk.i18n('TASK_ADD_REL_BUSINESS')+'</a>') : '',
                statusName: t.status == 1 && t.expired == "true" ? rk.i18n('TASK_IS_OVERDUE') : $this.data.taskStatus[t.status].name,
                statusClass: t.status == 1 && t.expired == "true" ? 'overdue' : 'normal',
                finishClass: t.status == 2 ? 'done' : 'normal',
                reminderName: {
                    '-1': rk.i18n('TASK_REMIND_NO'),
                    '0': rk.i18n('TASK_REMIND_ON_TIME'),
                    '300': rk.i18n('TASK_REMIND_BEFORE_300'),
                    '600': rk.i18n('TASK_REMIND_BEFORE_600'),
                    '1800': rk.i18n('TASK_REMIND_BEFORE_1800'),
                    '3600': rk.i18n('TASK_REMIND_BEFORE_3600'),
                    '7200': rk.i18n('TASK_REMIND_BEFORE_7200'),
                    '21600': rk.i18n('TASK_REMIND_BEFORE_21600'),
                    '86400': rk.i18n('TASK_REMIND_BEFORE_86400'),
                    '172800': rk.i18n('TASK_REMIND_BEFORE_172800')
                }[t.reminder],
                members: $this.data.members.length ? ['<ul class="people_list task_people_list" joiner>', $.map($this.data.members, function(id) {
                    var o = $this.data.users[id];
                    o.icon = o.icon || DEFAULTS.USER_DEFAULT_ICON;
                    return rk.templateText('<li joinerid="{{id}}" title="{{name}}" icon="{{icon}}"><a href="javascript:;"><img src="{{icon}}"></a></li>', o);
                }).join(''), '</ul>'].join('') : ('<span class="task_list_noneinfo js-joiner-span">'+rk.i18n('TASK_HAVE_NO_SET')+'</span>'),

                typeName: t.ownerId == t.createdBy ? rk.i18n('TASK_CREATE') : rk.i18n('TASK_ASSIGN'),

                createdByName: $this.data.users[t.createdBy].name,
                createdByIcon: $this.data.users[t.createdBy].icon || DEFAULTS.USER_DEFAULT_ICON,

                updatedByName: $this.data.users[t.updatedBy].name,
                updatedByIcon: $this.data.users[t.updatedBy].icon || DEFAULTS.USER_DEFAULT_ICON,

                planFinishDateFmt: moment(t.planFinishDate - 0).format('YYYY-MM-DD HH:mm'),
                actualFinishDateFmt: moment(t.actualFinishDate - 0).format('YYYY-MM-DD HH:mm'),
                createdAtFmt: moment(t.createdAt - 0).format('YYYY-MM-DD HH:mm'),
                updatedAtFmt: moment(t.updatedAt - 0).format('YYYY-MM-DD HH:mm'),
                commentCount: $this.data.commentCount,
                fileCount: $this.data.files.length,

                taskReAssign: (isAdmin && t.status == 4) ? '' : 'hidden',
                taskOperateHidden: (isOwner && t.status == 3) ? '' : 'hidden',
                powerDelete: isAdmin ? '' : 'hidden',
                powerExit: isJoiner ? '' : 'hidden',
                powerEditDisabled: isAdmin || isOwner ? '' : 'disabled',
                powerCheckboxDisabled: isAdmin || isOwner ? '' : '_disabled',
                powerAssignerHidden: (isOwner && t.status == 3) ? 'hidden' : '',
                ownerEditHidden: isAdmin ? '' : 'hidden',
                powerEditHidden: isAdmin || isOwner ? '' : 'hidden',
                powerReminder: isAdmin || isOwner || isJoiner ? '' : 'hidden'
            });
        },
        _rendTaskDetail: function() {
            var $this = this,
                $elem = this.element,
                opt = this.options;
            var t = $this.data.task;
            var isAdmin = SESSION.user.id == t.createdBy,
                isOwner = SESSION.user.id == t.ownerId,
                isJoiner = $.inArray(SESSION.user.id, $this.data.members) > -1;
            var $detail = rk.templateText(require("oa/tmpl/task/tpl_task_content_detail.tpl"), t);
            $elem.html($detail);
            if (t.status == 4 && isAdmin) { //我分配的被人拒绝的全字段编辑
                var $statusCheck = $elem.find('a.js-status');
                $statusCheck.addClass('_disabled');
                $statusCheck.parent().attr('class', 'task_tickbox_disabled');
                $elem.find('div.task_status').remove();
                $elem.find('div.task_tool').remove();
                $elem.find('a.edit_link').remove();
                $elem.find('div.task_save').show();
                $this._addEventHandler();
            } else { //其它情况抠框编辑
                if (isJoiner) {
                    $elem.find('a.js-belong').remove();
                }
                if (t.status == 3) { //未接受状态不可以编辑
                    $elem.find('a.edit_link').remove();
                    $elem.find('div.js_edit_div').addClass('disabled');
                    var $statusCheck = $elem.find('a.js-status');
                    $statusCheck.addClass('_disabled');
                    $statusCheck.parent().attr('class', 'task_tickbox_disabled');
                    if (!isAdmin) {
                        $elem.find('a.js-delete').remove();
                        $elem.find('a.js-exit').remove();
                    }
                }
                $this._addDigHoleEventHandler();
            }
            $elem.find('a.hidden').remove();
            //初始化底部的讨论，附件和历史
            $this._initDetailBottom();
        },
        _addEventHandler: function() {
            var $this = this,
                $detail = this.element,
                opt = this.options;
            $this._delTask();
            //修改任务名称
            var $el = $detail.find('div.task_name');
            var oldVal = $el.text();
            var $nameInput = $('<input type="text" style="width:100%; height:30px; border:0; padding: 2px;" placeholder="'+rk.i18n('TASK_MUST_TASK_NAME')+'"/>').val(oldVal).data('oldVal', oldVal).appendTo($el.empty()).focus();
            //修改任务描述
            var $el = $detail.find('div.task_description');
            var oldVal = $el.find("span.task_list_noneinfo").size() ? '' : $el.text();
            var $desTextarea = $('<textarea style="width:100%; height:50px; border:0; padding: 2px;" placeholder="'+rk.i18n('TASK_INPUT_DESCRIPTION')+'"></textarea>').val(oldVal).data('oldVal', oldVal).appendTo($el.empty());
            //修改负责人
            var $ul = $detail.find('ul[ownerId]'),
                $label = $ul.prev();
            var oldVal = {
                ownerId: $ul.attr('ownerId'),
                ownerName: $ul.attr('ownerName'),
                ownerIcon: $ul.attr('ownerIcon')
            };
            $ul.remove();
            $label.data('oldVal', oldVal);
            var $elems = $('<div class="name_select">' + rk.templateText('<input class="text" id="taskOwnerInput" ownerId="{{ownerId}}" ownerName="{{ownerName}}" value="{{ownerName}}" type="text" style="width: 100px;"/>', oldVal) + '</div>').insertAfter($label);
            $elems.find('input').rkUser({
                onSelect: function(userId, userName) {
                    $('#taskOwnerInput').val(userName);
                    $('#taskOwnerInput').attr('ownerId', userId);
                    $('#taskOwnerInput').attr('ownerName', userName);
                }
            });
            //修改截止日期
            var $span = $detail.find('span.js-deadline-span'),
                $label = $span.prev(),
                oldVal = $span.text(),
                arOld = oldVal.split(' '),
                oldDate = arOld[0],
                oldTime = arOld[1];
            $span.remove();
            $label.data('oldVal', oldVal);
            var $elems = $('<div class="field_content"><div class="date_area clear"><span class="data_picker"></span><input type="text" class="date" title="'+rk.i18n('TASK_END_DATE')+'"/></div><div class="time_area clear"><span class="time_picker"></span><input type="text" class="time" title="'+rk.i18n('TASK_END_TIME')+'"/></div></div>').insertAfter($label);
            var $iptDate = $elems.find('input.date').val(oldDate).datepicker({
                changeMonth: true,
                changeYear: true
            });
            var $iptTime = $elems.find('input.time').val(oldTime).timepicker();
            //修改提醒
            var $span = $detail.find('span[reminder]'),
                $label = $span.prev(),
                oldVal = $span.attr('reminder');
            $span.remove();
            var $elems = $('<span class="ui-select-buttonset"><select id="dlt_reminder_detail_modify">' +
            '<option value="-1">'+rk.i18n('TASK_REMIND_NO')+'</option>' +
            '<option value="0">'+rk.i18n('TASK_REMIND_ON_TIME')+'</option>' +
            '<option value="300">'+rk.i18n('TASK_REMIND_BEFORE_300')+'</option>' +
            '<option value="600">'+rk.i18n('TASK_REMIND_BEFORE_600')+'</option>' +
            '<option value="1800">'+rk.i18n('TASK_REMIND_BEFORE_1800')+'</option>' +
            '<option value="3600">'+rk.i18n('TASK_REMIND_BEFORE_3600')+'</option>' +
            '<option value="7200">'+rk.i18n('TASK_REMIND_BEFORE_7200')+'</option>' +
            '<option value="21600">'+rk.i18n('TASK_REMIND_BEFORE_21600')+'</option>' +
            '<option value="86400">'+rk.i18n('TASK_REMIND_BEFORE_86400')+'</option>' +
            '<option value="172800">'+rk.i18n('TASK_REMIND_BEFORE_172800')+'</option>' +
            '</select></span>').insertAfter($label);
            var $reminder = $('#dlt_reminder_detail_modify');
            $reminder.val(oldVal);
            $reminder.selectmenu({
                appendTo: 'body'
            });
            //修改参与人
            var $ul = $detail.find('ul[joiner]'),
                $span = $detail.find('span.js-joiner-span'),
                $label,
                oldVal;
            if ($ul.size() < 1) {
                $label = $span.prev();
                $span.remove();
            } else {
                $label = $ul.prev();
                oldVal = $ul.find('li').map(function(i, li) {
                    var $li = $(li);
                    return {
                        id: $li.attr('joinerid'),
                        name: $li.attr('title'),
                        icon: $li.attr('icon')
                    };
                }).get();
                $ul.remove();
            }
            $('<div class="name_select"><input type="text" id="taskJoinerInput"/></div>').insertAfter($label);
            $('#taskJoinerInput').multipeopleselector({
                menuWidth: 320,
                position: {
                    my: 'left top+2'
                }
            });
            if ($ul.size() > 0) {
                var joinerV = [];
                $.each(oldVal, function(i, o) {
                    joinerV.push({
                        label: o.name,
                        value: o.id,
                        pic: o.icon
                    });
                });
                $('#taskJoinerInput').multipeopleselector("val", joinerV);
            }
            //添加关联业务
            var $elems = $('#task_business_div');
            if ($this.data.sourceEntity.id == '') {
                $elems.empty();

                var url = '/json/crm_func/get-crm-func.action';
                rk.post(url, {}).done(function (json) {
                    if (json.status == 0) {
                        SESSION.func = json.data.permission.func;

                        $elems.append(rk.templateText(require("oa/tmpl/task/tpl_task_content_business_edit.tpl"),{SESSION:SESSION}));
                    } else {
                        $.msg(rk.i18n('LOAD_ERROR'));
                    }
                });

                //$elems.append(rk.templateText(require("oa/tmpl/task/tpl_task_content_business_edit.tpl"),{SESSION:SESSION}));
                if(SESSION.tenantType == 1){
                    $this._business_autocomplete("6");
                }else {
                    $this._business_autocomplete("1");
                }
                //$this._accountAutoComplete();
                //$this._oppAutoComplete();
                //$this._contactAutoComplete();
                //$this._leadAutoComplete();
                //$this._campaignAutoComplete();
                $this._typeChange();
            }
            $detail.find('#reAssignBtn').on('click', function() {
                var nameVal = $.trim($nameInput.val());
                if (!nameVal) {
                    $.msg(rk.i18n('TASK_NAME_NOT_BLANK'));
                    return $nameInput.focus();
                }
                var desVal = $.trim($desTextarea.val());
                if (desVal && desVal.length > 500) {
                    $.msg(rk.i18n('TASK_DESCRIPTION_NOT_MORE_THAN'));
                    return $desTextarea.focus();
                }
                var ownerIdVal = $('#taskOwnerInput').attr('ownerId'),
                    ownerNameVal = $('#taskOwnerInput').attr('ownerName');
                if (ownerNameVal != $.trim($('#taskOwnerInput').val()) || !ownerIdVal) {
                    $.msg(rk.i18n('TASK_OWNER_IS_ERROR'));
                    return $('#taskOwnerInput').focus();
                }
                var date = $.trim($iptDate.val()),
                    time = $.trim($iptTime.val()),
                    val = [date, time].join(' ');
                if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
                    $.msg(date ? rk.i18n('TASK_INPUT_END_DATE') : rk.i18n('TASK_SELECT_END_DATE'));
                    return false;
                }
                if (!/^\d{2}:\d{2}$/.test(time)) {
                    $.msg(time ? rk.i18n('TASK_INPUT_END_TIME') : rk.i18n('TASK_SELECT_END_TIME'));
                    return false;
                }
                var memberIds = $.map($('#taskJoinerInput').multipeopleselector("val"), function(k) {
                    return k.value;
                }).join(',');
                //$(this).beLoading();
                $.post('/json/crm_task/re-assign-task.action', {
                    "taskId": opt.taskId,
                    "paramMap.belongId": $('#object_id').val() ? $('#belong_id').val() : '',
                    "paramMap.objectId": $('#object_id').val(),
                    "memberIds": memberIds,
                    "paramMap.taskName": nameVal,
                    "paramMap.description": desVal,
                    "paramMap.ownerId": ownerIdVal,
                    'paramMap.planFinishDate': date,
                    'paramMap.planFinishTime': time,
                    "remind": $reminder.val()
                }, null, 'json').done(function(json) {
                    if (json.status == 0) {
                        rk.oa.closeContent();
                        rk.oa.popupCurtain({
                            onSuccess: function(curtainElem) {
                                curtainElem.taskCurtainCtrl({
                                    aType: 'beRejected',
                                    viewType: null
                                });
                            }
                        });
                        $.msg(rk.i18n('TASK_ASSIGN_SUCCESS'), 1);
                    } else {
                        $.msg(rk.i18n('TASK_ASSIGN_ERROR'));
                    }
                }).fail(function(def, code, message) {
                    def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                });
            });
        },
        _delTask: function() {
            var $this = this,
                $detail = this.element,
                opt = this.options;
            $detail.find('a.js-delete').on('click', function() {
                var $el = $(this);
                rk.confirm(rk.i18n('TASK_TEXT_6')+'【' + $this.data.task.name + '】'+rk.i18n('TASK_TEXT_7'), function() {
                    $.post('/json/crm_task/delete.action', {
                        taskId: opt.taskId
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            $('div[_taskId=' + opt.taskId + ']').remove();
                            rk.oa.closeContent();
                            $.msg(rk.i18n('TASK_DELETE_SUCCESS'), 1);
                        } else {
                            $.msg(rk.i18n('TASK_DELETE_ERROR'));
                        }
                    }).fail(function(def, code, message) {
                        def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                    });
                });
            });
        },
        _changeStatus: function($el) {
            var me = this,
                elem = me.element,
                opt = me.options;
            var checked = $el.hasClass('done');
            $.post('/json/crm_task/change-status.action', {
                taskId: opt.taskId,
                taskStatus: checked ? 1 : 2
            }, null, 'json').done(function(json) {
                if (json.status == 0) {
                    if (checked) {
                        $el.removeClass('done').addClass('normal').attr('title', rk.i18n('TASK_CLICK_FINISHED'));
                        $('a[_taskId=' + opt.taskId + ']').removeClass('done').addClass('normal').attr('title', rk.i18n('TASK_CLICK_FINISHED'));
                        $.msg(rk.i18n('TASK_RESTART_SUCCESS'), 1);
                    } else {
                        $el.removeClass('normal').addClass('done').attr('title', rk.i18n('TASK_CLICK_CANCEL_FINISHED'));
                        $('a[_taskId=' + opt.taskId + ']').removeClass('normal').addClass('done').attr('title', rk.i18n('TASK_CLICK_CANCEL_FINISHED'));
                        $.msg(rk.i18n('TASK_HAVE_FINISHED'), 1);
                    }
                } else {
                    $.msg(rk.i18n('TASK_CHANGE_STATUS_ERROR'));
                }
            }).fail(function(def, code, message) {
                def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
            });
        },
        _addDigHoleEventHandler: function() {
            var $this = this,
                $detail = this.element,
                opt = this.options;
            var entryid = opt.taskId,
                entryname = $this.data.task.name,
                btnHtml = '<div class="edit_save"><a href="javascript:;" act="save">'+rk.i18n('TASK_SAVE')+'</a> <a class="canel_button" href="javascript:;" act="cancel">'+rk.i18n('TASK_CANCEL')+'</a></div>';
            //接受任务
            $detail.find('#btnAcceptTask').on('click', function(evt) {
                evt.preventDefault();
                $.post('/json/crm_task/accept.action', {
                    taskId: entryid
                }, null, 'json').done(function(json) {
                    if (json.status == 0) {
                        rk.oa.closeContent();
                        rk.oa.popupCurtain({
                            onSuccess: function(curtainElem) {
                                curtainElem.taskCurtainCtrl({
                                    aType: 'toMe',
                                    viewType: null
                                });
                            }
                        });
                        $.msg(rk.i18n('TASK_ACCEPT_SUCCESS'), 1);
                    } else {
                        $.msg(rk.i18n('TASK_ACCEPT_ERROR'));
                    }
                }).fail(function(def, code, message) {
                    def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                });
            });
            //拒绝任务
            $detail.find('#btnRejectTask').on('click', function(evt) {
                evt.preventDefault();
                $('#rejectTaskDiv').show();
            });
            $detail.find('#btnRejectSubmit').on('click', function(evt) {
                evt.preventDefault();
                var content = $.trim($("#rejectTaskInput").val());
                if (content.length > 0) {
                    if (content.length > 100) {
                        $("#rejectTaskInput").focus();
                        $.msg(rk.i18n('TASK_REJECT_NOT_MORE_THAN'));
                        return false;
                    }
                    $.post('/json/crm_task/reject.action', {
                        taskId: entryid,
                        content: content
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            rk.oa.closeContent();
                            rk.oa.popupCurtain({
                                onSuccess: function(curtainElem) {
                                    curtainElem.taskCurtainCtrl({
                                        aType: 'toMe',
                                        viewType: null
                                    });
                                }
                            });
                            $.msg(rk.i18n('TASK_REJECT_SUCCESS'), 1);
                        } else {
                            $.msg(rk.i18n('TASK_REJECT_ERROR'));
                        }
                    });
                } else {
                    $.msg(rk.i18n('TASK_INPUT_REJECT'))
                }
            });
            //修改任务状态
            $detail.find('a.js-status:not(._disabled)').on('click', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    checked = $el.hasClass('done');
                if (checked) {
                    rk.confirm(rk.i18n('TASK_IS_RESTART'), function() {
                        $this._changeStatus($el);
                    });
                } else {
                    $this._changeStatus($el);
                }
            });
            //删除任务
            $this._delTask();
            //退出任务
            $detail.find('a.js-exit').on('click', function() {
                var $el = $(this);
                rk.confirm(rk.i18n('TASK_TEXT_4')+'【' + entryname + '】'+rk.i18n('TASK_TEXT_5'), function() {
                    $.post('/json/crm_task/quit.action', {
                        taskId: entryid
                    }, null, 'json').done(function(json) {
                        if (json.status == 0) {
                            //$elem.taskList();
                            //$detail.remove();
                            $('div[_taskId=' + entryid + ']').remove();
                            rk.oa.closeContent();
                            $.msg(rk.i18n('TASK_QUIT_SUCCESS'), 1);
                        } else {
                            $.msg(rk.i18n('TASK_QUIT_ERROR'));
                        }
                    }).fail(function(def, code, message) {
                        def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                    });
                });
            });
            //修改任务名称
            $detail.find('div.task_name:not(.disabled)').on('click', function() {
                var $el = $(this),
                    oldVal;
                if (!$el.hasClass('editing')) {
                    $el.addClass('editing');
                    oldVal = $el.text();
                    var $ipt = $('<input type="text" style="width:100%; height:30px; border:0; padding: 2px;" placeholder="'+rk.i18n('TASK_MUST_TASK_NAME')+'"/>').val(oldVal).data('oldVal', oldVal).appendTo($el.empty()).focus().select();
                    $ipt.on('blur', function(evt) {
                        var val = $.trim($ipt.val());
                        if (val) {
                            if (val == oldVal) {
                                $el.text(val);
                                $el.removeClass('editing');
                            } else {
                                $.post('/json/crm_task/simple-update.action', {
                                    taskId: entryid,
                                    title: val
                                }, null, 'json').done(function(json) {
                                    if (json.status == 0) {
                                        $ipt.data('oldVal', val);
                                        $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                        $el.text(val);
                                        $el.removeClass('editing');
                                    } else {
                                        $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                                    }
                                }).fail(function(def, code, message) {
                                    def.status != 0 && rk.msg(rk.i18n('LOAD_ERROR'));
                                });
                            }
                        } else {
                            $.msg(rk.i18n('TASK_NAME_NOT_BLANK'));
                        }
                    });
                }
            });
            //修改任务描述
            $detail.find('div.task_description:not(.disabled)').on('click', function() {
                var $el = $(this),
                    oldVal;
                if (!$el.hasClass('editing')) {
                    $el.addClass('editing');
                    oldVal = $el.find("span.task_list_noneinfo").size() ? '' : $el.html();
                    oldVal = oldVal.replace(/<br>/g, '\n');
                    var $ipt = $('<textarea style="width:100%; height:50px; border:0; padding: 2px;" placeholder="'+rk.i18n('TASK_INPUT_DESCRIPTION')+'"></textarea>').val(oldVal).data('oldVal', oldVal).appendTo($el.empty()).focus();
                    $ipt.on('blur', function(evt) {
                        var val = $.trim($ipt.val());
                        if (val == oldVal) {
                            $el.html(val.replace(/\n/g, '<br>'));
                            $el.removeClass('editing');
                            if ($.trim(val) == '') {
                                $el.html('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_DESCRIPTION')+'</span>');
                            }
                        } else {
                            if (val && val.length > 500) {
                                $.msg(rk.i18n('TASK_DESCRIPTION_NOT_MORE_THAN'));
                                return $el.focus();
                            }
                            $.post('/json/crm_task/simple-update.action', {
                                taskId: entryid,
                                descr: val
                            }, null, 'json').done(function(json) {
                                if (json.status == 0) {
                                    $ipt.data('oldVal', val);
                                    $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                    $el.html(val.replace(/\n/g, '<br>'));
                                    $el.removeClass('editing');
                                    if ($.trim(val) == '') {
                                        $el.html('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_DESCRIPTION')+'</span>');
                                    }
                                } else {
                                    $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                                }
                            }).fail(function(def, code, message) {
                                def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                            });
                        }
                    });
                }
            });
            //修改负责人
            $detail.on('click', 'a.js-owner:not(.disabled)', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    $ul = $el.prev(),
                    $label = $ul.prev(),
                    oldVal = {
                        ownerId: $ul.attr('ownerId'),
                        ownerName: $ul.attr('ownerName'),
                        ownerIcon: $ul.attr('ownerIcon')
                    };
                $el.add($ul).remove();
                $label.data('oldVal', oldVal);
                var $elems = $('<div class="name_select">' + rk.templateText('<input class="text" id="taskOwnerInput" ownerId="{{ownerId}}" value="{{ownerName}}" type="text" style="width: 100px;"/>', oldVal) + '</div>' + btnHtml).insertAfter($label);
                $elems.find('input').rkUser({
                    onSelect: function(userId, userName) {
                        $('#taskOwnerInput').val(userName);
                        $('#taskOwnerInput').attr('ownerId', userId);
                    }
                });
                $elems.find('a[act="save"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var $ipt = $elems.find('#taskOwnerInput'),
                        val = $ipt.attr('ownerId');
                    if (val) {
                        if (val == oldVal.ownerId) {
                            $elems.find('a[act="cancel"]').trigger('click');
                        } else {
                            $.post('/json/crm_task/change-owner.action', {
                                taskId: entryid,
                                ownerId: val
                            }, null, 'json').done(function(json) {
                                if (json.status == 0) {
                                    json.data = $.parseJSON(json.data);
                                    $label.data('oldVal', {
                                        ownerId: json.data.id,
                                        ownerName: json.data.name,
                                        ownerIcon: json.data.icon || DEFAULTS.USER_DEFAULT_ICON
                                    });
                                    $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                    $elems.find('a[act="cancel"]').trigger('click');
                                    if (!seajs.data.isFinal) {
                                        rk.oa.popupContent({
                                            onSuccess: function (contentElem) {
                                                contentElem.taskContentCtrl({
                                                    taskId: entryid
                                                });
                                            }
                                        });
                                    }
                                } else {
                                    $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                                }
                            }).fail(function(def, code, message) {
                                def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                            });
                        }
                    } else {
                        $.msg(rk.i18n('TASK_OWNER_NOT_BLANK'));
                    }
                });

                $elems.find('a[act="cancel"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var val = $label.data('oldVal');
                    $label.nextAll().remove();
                    $(rk.templateText('<ul class="people_list task_people_list" ownerName="{{ownerName}}" ownerid="{{ownerId}}" ownerIcon="{{ownerIcon}}"><li><a href="javascript:;" title="{{ownerName}}"><img src="{{ownerIcon}}" alt=""></a></li></ul><a class="edit_link js-owner" href="javascript:;">'+rk.i18n('TASK_UPDATE_OWNER')+'</a>', val)).insertAfter($label);
                });

            });

            $detail.on('click', 'a.js-deadline:not(.disabled)', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    $span = $el.prev(),
                    $label = $span.prev(),
                    oldVal = $span.text(),
                    arOld = oldVal.split(' '),
                    oldDate = arOld[0],
                    oldTime = arOld[1];
                $el.add($span).remove();

                $label.data('oldVal', oldVal);
                var $elems = $('<div class="field_content"><div class="date_area clear"><span class="data_picker"></span><input type="text" class="date" title="'+rk.i18n('TASK_END_DATE')+'"/></div><div class="time_area clear"><span class="time_picker"></span><input type="text" class="time" title="'+rk.i18n('TASK_END_TIME')+'"/></div></div>' + btnHtml).insertAfter($label);
                var $iptDate = $elems.find('input.date').val(oldDate).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                var $iptTime = $elems.find('input.time').val(oldTime).timepicker();

                $elems.find('a[act="save"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var date = $.trim($iptDate.val()),
                        time = $.trim($iptTime.val()),
                        val = [date, time].join(' ');
                    if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
                        $.msg(date ? rk.i18n('TASK_INPUT_END_DATE') : rk.i18n('TASK_SELECT_END_DATE'));
                        return $iptDate.focus();
                    }
                    if (!/^\d{2}:\d{2}$/.test(time)) {
                        $.msg(time ? rk.i18n('TASK_INPUT_END_TIME') : rk.i18n('TASK_SELECT_END_TIME'));
                        return $iptTime.focus();
                    }
                    if (val == oldVal) {
                        $elems.find('a[act="cancel"]').trigger('click');
                    } else {
                        var arTime = time.split(':'),
                            hour = parseInt(arTime[0], 10),
                            minute = parseInt(arTime[1], 10),
                            ms = (hour * 3600 + minute * 60) * 1000;
                        $.post('/json/crm_task/change-plan-date.action', {
                            taskId: entryid,
                            planDate: $iptDate.datepicker('getDate').getTime() + ms
                        }, null, 'json').done(function(json) {
                            if (json.status == 0) {
                                $label.data('oldVal', val);
                                $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                $elems.find('a[act="cancel"]').trigger('click');
                            } else {
                                $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                            }
                        }).fail(function(def, code, message) {
                            def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                        });
                    }
                });

                $elems.find('a[act="cancel"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var val = $label.data('oldVal');
                    $elems.off('click');
                    $label.nextAll().remove();
                    $('<span>' + val + '</span><a class="edit_link js-deadline" href="javascript:;">'+rk.i18n('TASK_UPDATE_END_TIME')+'</a>').insertAfter($label);
                });
            });

            $detail.on('click', 'a.js-reminder:not(.disabled)', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    $span = $el.prev(),
                    $label = $span.prev(),
                    oldVal = $span.attr('reminder');
                $el.add($span).remove();

                var $elems = $('<span class="ui-select-buttonset"><select id="dlt_reminder_detail_modify">' +
                '<option value="-1">'+rk.i18n('TASK_REMIND_NO')+'</option>' +
                '<option value="0">'+rk.i18n('TASK_REMIND_ON_TIME')+'</option>' +
                '<option value="300">'+rk.i18n('TASK_REMIND_BEFORE_300')+'</option>' +
                '<option value="600">'+rk.i18n('TASK_REMIND_BEFORE_600')+'</option>' +
                '<option value="1800">'+rk.i18n('TASK_REMIND_BEFORE_1800')+'</option>' +
                '<option value="3600">'+rk.i18n('TASK_REMIND_BEFORE_3600')+'</option>' +
                '<option value="7200">'+rk.i18n('TASK_REMIND_BEFORE_7200')+'</option>' +
                '<option value="21600">'+rk.i18n('TASK_REMIND_BEFORE_21600')+'</option>' +
                '<option value="86400">'+rk.i18n('TASK_REMIND_BEFORE_86400')+'</option>' +
                '<option value="172800">'+rk.i18n('TASK_REMIND_BEFORE_172800')+'</option>' +
                '</select></span>' + btnHtml).insertAfter($label);
                var $reminder = $('#dlt_reminder_detail_modify');
                $reminder.val(oldVal);
                $reminder.data('oldVal', oldVal);
                $reminder.selectmenu({
                    appendTo: 'body'
                });

                $elems.find('a[act="save"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var val = $reminder.val();
                    if (val == oldVal) {
                        $elems.find('a[act="cancel"]').trigger('click');
                    } else {
                        $.post('/json/crm_task/change-reminder.action', {
                            taskId: entryid,
                            time: val
                        }, null, 'json').done(function(json) {
                            if (json.status == 0) {
                                $reminder.data('oldVal', val);
                                $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                $elems.find('a[act="cancel"]').trigger('click');
                            } else {
                                $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                            }
                        }).fail(function(def, code, message) {
                            def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                        });
                    }
                });

                $elems.find('a[act="cancel"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var val = $reminder.data('oldVal');
                    $label.nextAll().remove();
                    $('<span reminder="' + val + '">' + {
                        '-1': rk.i18n('TASK_REMIND_NO'),
                        '0': rk.i18n('TASK_REMIND_ON_TIME'),
                        '300': rk.i18n('TASK_REMIND_BEFORE_300'),
                        '600': rk.i18n('TASK_REMIND_BEFORE_600'),
                        '1800': rk.i18n('TASK_REMIND_BEFORE_1800'),
                        '3600': rk.i18n('TASK_REMIND_BEFORE_3600'),
                        '7200': rk.i18n('TASK_REMIND_BEFORE_7200'),
                        '21600': rk.i18n('TASK_REMIND_BEFORE_21600'),
                        '86400': rk.i18n('TASK_REMIND_BEFORE_86400'),
                        '172800': rk.i18n('TASK_REMIND_BEFORE_172800')
                    }[val] + '</span><a class="edit_link js-reminder" href="javascript:;">'+rk.i18n('TASK_UPDATE_REMIND')+'</a>').insertAfter($label);
                });
            });

            $detail.on('click', 'a.js-joiner:not(.disabled)', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    $ul = $el.prev(),
                    $label = $ul.prev(),
                    oldVal = $ul.find('li').map(function(i, li) {
                        var $li = $(li);
                        return {
                            id: $li.attr('joinerid'),
                            name: $li.attr('title'),
                            icon: $li.attr('icon')
                        };
                    }).get();
                $el.add($ul).remove();

                $label.data('oldVal', oldVal);
                var $elems = $('<div class="name_select"><input type="text" id="taskJoinerInput"/></div>' + btnHtml).insertAfter($label);
                $('#taskJoinerInput').multipeopleselector({
                    menuWidth: 320,
                    position: {
                        my: 'left top+2'
                    }
                });
                var joinerV = [];
                $.each(oldVal, function(i, o) {
                    joinerV.push({
                        label: o.name,
                        value: o.id,
                        pic: o.icon
                    });
                });
                $('#taskJoinerInput').multipeopleselector("val", joinerV);
                $elems.find('a[act="save"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var $ipt = $elems.find('#taskJoinerInput'),
                        val = $.map($ipt.multipeopleselector("val"), function(k) {
                            return k.value;
                        });
                    if (val.sort().join(',') == $.map(oldVal, function(o) {
                            return o.id;
                        }).sort().join(',')) {
                        $elems.find('a[act="cancel"]').trigger('click');
                    } else {
                        $.post('/json/crm_task/change-member.action', {
                            taskId: entryid,
                            memberIds: val.join(',')
                        }, null, 'json').done(function(json) {
                            if (json.status == 0) {
                                json.data = $.parseJSON(json.data);
                                $label.data('oldVal', json.data);
                                $.msg(rk.i18n('TASK_UPDATE_SUCCESS'), 1);
                                $elems.find('a[act="cancel"]').trigger('click');
                                if (!seajs.data.isFinal) {
                                    rk.oa.popupContent({
                                        onSuccess: function (contentElem) {
                                            contentElem.taskContentCtrl({
                                                taskId: entryid
                                            });
                                        }
                                    });
                                }
                            } else {
                                $.msg(rk.i18n('TASK_UPDATE_ERROR'));
                            }
                        }).fail(function(def, code, message) {
                            def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                        });
                    }
                });

                $elems.find('a[act="cancel"]').on('click', function(evt) {
                    evt.preventDefault();
                    evt.stopPropagation();
                    var val = $label.data('oldVal');
                    $label.nextAll().remove();
                    $((val.length ? ['<ul class="people_list task_people_list">', $.map(val, function(o) {
                        o.icon = o.icon || DEFAULTS.USER_DEFAULT_ICON;
                        return rk.templateText('<li joinerid="{{id}}" title="{{name}}" icon="{{icon}}"><a href="javascript:;"><img src="{{icon}}"></a></li>', o);
                    }).join(''), '</ul>'].join('') : ('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_SET')+'</span>')) + '<a class="edit_link js-joiner" title="" href="javascript:;">'+rk.i18n('TASK_UPDATE_MEMBER')+'</a>').insertAfter($label);

                });
            });

            //添加关联业务
            $detail.on('click', 'a.js-belong', function(evt) {
                evt.preventDefault();
                var $el = $(this),
                    $span = $el.prev();
                $el.add($span).remove();
                var $elems = $('#task_business_div');

                var url = '/json/crm_func/get-crm-func.action';
                rk.post(url, {}).done(function (json) {
                    if (json.status == 0) {
                        SESSION.func = json.data.permission.func;
                        $elems.append(rk.templateText(require("oa/tmpl/task/tpl_task_content_business_edit.tpl"),{SESSION:SESSION}) + btnHtml);
                        
                        if(SESSION.tenantType == 1){
                            $this._business_autocomplete("6");
                        }else {
                            $this._business_autocomplete("1");
                        }
                        
                        $this._typeChange();
                        
                        $elems.find('a[act="save"]').on('click', function(evt) {
                            evt.preventDefault();
                            evt.stopPropagation();
                            var val = $('#object_id').val();
                            if (val) {
                                var belongId = $('#belong_id').val();
                                $.post('/json/crm_task/simple-update.action', {
                                    taskId: entryid,
                                    belongId: belongId,
                                    objectId: val
                                }, null, 'json').done(function(json) {
                                    if (json.status == 0) {
                                        $elems.empty();
                                        $elems.append(rk.templateText(
                                            '<span class="task_group"><p class="feed-group-name"><span title="{{belongName}}" class="feed-group-class {{belongClass}}"></span><a title="{{objectName}}" href="{{objectpage}}" target="_blank" class="">{{objectName}}</a></p></span>', {
                                                belongName: $this.rMap[belongId].name,
                                                belongClass: $this.rMap[belongId].cname,
                                                objectpage: $this.rMap[belongId].url + belongId,
                                                objectName: json.data
                                            }
                                        ));
                                        $.msg(rk.i18n('TASK_ADD_SUCCESS'), 1);
                                        $elems.find('a[act="cancel"]').trigger('click');
                                    } else {
                                        $.msg(rk.i18n('TASK_ADD_ERROR'));
                                    }
                                }).fail(function(def, code, message) {
                                    def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                                });
                            } else {
                                $elems.find('a[act="cancel"]').trigger('click');
                            }
                        });
                       $elems.find('a[act="cancel"]').on('click', function(evt) {
                       evt.preventDefault();
                       evt.stopPropagation();
                       $elems.empty();
                       $elems.append('<span class="task_list_noneinfo">'+rk.i18n('TASK_HAVE_NO_SET')+'</span><a class="edit_link js-belong" title="" href="javascript:;">'+rk.i18n('TASK_ADD_REL_BUSINESS')+'</a>');
                       });
                    } else {
                        $.msg(rk.i18n('LOAD_ERROR'));
                    }
                });
                //$elems.append(rk.templateText(require("oa/tmpl/task/tpl_task_content_business_edit.tpl"),{SESSION:SESSION}) + btnHtml);
                //$this._accountAutoComplete();
                //$this._oppAutoComplete();
                //$this._contactAutoComplete();
                //$this._leadAutoComplete();
                //$this._campaignAutoComplete();
            });
        },
        _accountAutoComplete: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#account" + _suffix).autocomplete({
                source: function(request, response) {
                    var url = "/json/oa_search/search-account.action";
                    var key = request.term;
                    $.ajax({
                        url: url,
                        type: 'POST',
                        minLength: -1,
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase(),
                            accountTypes: 1
                        },
                        dataType: "json",
                        success: function(data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }
                                }
                                me._account(id, _suffix)
                            } else {
                                me._account(undefined, _suffix)
                            }
                            response(data);
                        },
                        error: function() {
                            response([]);
                        }
                    });
                },
                select: function(event, ui) {
                    var id = ui.item.value;
                    $("#object_id" + _suffix).val(id);
                    $("#account" + _suffix).val(ui.item.label);
                    if ($("#account_search_msg" + _suffix).length > 0) {
                        $("#account_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_ACCOUNT'));
                    }
                    return false;
                }
            });
        },
        _account: function(id, _suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            if (id != undefined) {
                $("#account_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_ACCOUNT')).show();
                $("#object_id" + _suffix).val(id);
            } else {
                $("#account_search_msg" + _suffix).html(rk.i18n('TASK_REL_ACCOUNT_NOT_EXIST')).show();
                $("#object_id" + _suffix).val("");
            }
        },
        _oppAutoComplete: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#opp" + _suffix).autocomplete({
                source: function(request, response) {
                    var key = request.term;
                    $.ajax({
                        url: "/json/oa_search/search-opp.action",
                        type: 'GET',
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase()
                        },
                        dataType: "json",
                        success: function(data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }
                                }
                                me._opp(id, _suffix)
                            } else {
                                me._opp(undefined, _suffix)
                            }
                            response(data);
                        },
                        error: function() {
                            response([]);
                        }
                    });
                },
                select: function(event, ui) {
                    var id = ui.item.value;
                    $("#object_id" + _suffix).val(id);
                    $("#opp" + _suffix).val(ui.item.label);
                    if ($("#opp_search_msg" + _suffix).length > 0) {
                        $("#opp_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_OPP'));
                    }
                    return false;
                }
            });
        },
        _opp: function(id, _suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            if (id != undefined) {
                $("#opp_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_OPP')).show();
                $("#object_id" + _suffix).val(id);
            } else {
                $("#opp_search_msg" + _suffix).html(rk.i18n('TASK_REL_OPP_NOT_EXIST')).show();
                $("#object_id" + _suffix).val("");
            }
        },
        _contactAutoComplete: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#contact" + _suffix).autocomplete({
                source: function(request, response) {
                    var url = "/json/oa_search/search-contact.action";
                    var key = request.term;
                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase()
                        },
                        dataType: "json",
                        success: function(data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }
                                }
                                me._contact(id, _suffix)
                            } else {
                                me._contact(undefined, _suffix)
                            }
                            response(data);
                        },
                        error: function() {
                            response([]);
                        }
                    });
                },
                minLength: 1,
                select: function(event, ui) {
                    var id = ui.item.value;
                    $("#object_id" + _suffix).val(id);
                    $("#contact" + _suffix).val(ui.item.label);
                    if ($("#contact_search_msg" + _suffix).length > 0) {
                        $("#contact_search_msg").html(rk.i18n('TASK_SYSTEM_AUTO_REL_CONTACT')).show();
                    }
                    return false;
                }
            });
        },
        _contact: function(id, _suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            if (id != undefined) {
                $("#contact_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_CONTACT')).show();
                $("#object_id" + _suffix).val(id);
            } else {
                $("#contact_search_msg" + _suffix).html(rk.i18n('TASK_REL_CONTACT_NOT_EXIST')).show();
                $("#contactId").val("");
            }
        },
        _leadAutoComplete: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#lead" + _suffix).autocomplete({
                source: function(request, response) {
                    var key = request.term;
                    $.ajax({
                        url: "/json/oa_search/search-lead.action",
                        type: 'GET',
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase()
                        },
                        dataType: "json",
                        success: function(data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }
                                }
                                me._lead(id, _suffix)
                            } else {
                                me._lead(undefined, _suffix)
                            }
                            response(data);
                        },
                        error: function() {
                            response([]);
                        }
                    });
                },
                select: function(event, ui) {
                    var id = ui.item.value;
                    $("#object_id" + _suffix).val(id);
                    $("#lead" + _suffix).val(ui.item.label);
                    var leadSearchMsg = $("#lead_search_msg" + _suffix);
                    if (leadSearchMsg.length > 0) {
                        leadSearchMsg.html(rk.i18n('TASK_SYSTEM_AUTO_REL_LEAD'));
                    }
                    return false;
                }
            });
        },
        _lead: function(id, _suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            if (id != undefined) {
                $("#lead_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_LEAD')).show();
                $("#object_id" + _suffix).val(id);
            } else {
                $("#lead_search_msg" + _suffix).html(rk.i18n('TASK_REL_LEAD_NOT_EXIST')).show();
                $("#object_id" + _suffix).val("");
            }
        },
        _campaignAutoComplete: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#campaign" + _suffix).autocomplete({
                source: function(request, response) {
                    var key = request.term;
                    $.ajax({
                        url: "/json/oa_search/search-campaign.action",
                        type: 'GET',
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase()
                        },
                        dataType: "json",
                        success: function(data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }
                                }
                                me._campaign(id, _suffix)
                            } else {
                                me._campaign(undefined, _suffix)
                            }
                            response(data);
                        },
                        error: function() {
                            response([]);
                        }
                    });
                },
                select: function(event, ui) {
                    var id = ui.item.value;
                    $("#object_id" + _suffix).val(id);
                    $("#campaign" + _suffix).val(ui.item.label);
                    var campaignSearchMsg = $("#campaign_search_msg" + _suffix);
                    if (campaignSearchMsg.length > 0) {
                        campaignSearchMsg.html(rk.i18n('TASK_SYSTEM_AUTO_REL_CAMPAIGN'));
                    }
                    return false;
                }
            });
        },
        _campaign: function(id, _suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            if (id != undefined) {
                $("#campaign_search_msg" + _suffix).html(rk.i18n('TASK_SYSTEM_AUTO_REL_CAMPAIGN')).show();
                $("#object_id" + _suffix).val(id);
            } else {
                $("#campaign_search_msg" + _suffix).html(rk.i18n('TASK_REL_CAMPAIGN_NOT_EXIST')).show();
                $("#object_id" + _suffix).val("");
            }
        },
        _business_autocomplete:function(val){
            var me = this;
            var elem = me.element;
            var opt = me.options;
            var valueJson = {
                "1": {
                    name: "account",
                    url: "/json/oa_search/search-account.action",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('TASK_TEXT_13'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_ACCOUNT_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_ACCOUNT')
                },
                "2": {
                    name: "opp",
                    url: "/json/oa_search/search-opp.action",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('TASK_TEXT_14'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_OPP_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_OPP')
                },
                "3": {
                    name: "contact",
                    url: "/json/oa_search/search-contact.action",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('TASK_TEXT_15'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_CONTACT_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_CONTACT')
                },
                "4": {
                    name: "lead",
                    url: "/json/oa_search/search-lead.action",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('TASK_TEXT_16'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_LEAD_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_LEAD')
                },
                "5": {
                    name: "campaign",
                    url: "/json/oa_search/search-campaign.action",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('TASK_TEXT_17'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_CAMPAIGN_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_CAMPAIGN')
                },
                "6": {
                    name: "agent",
                    url: "/json/crm_search/all-accounts.action?accountType=4",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('OBJECT_AGENT'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_AGENT_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_AGENT')
                },
                "7": {
                    name: "terminal",
                    url: "/json/crm_search/all-accounts.action?accountType=5",
                    placeholder: rk.i18n('TASK_TEXT_18'),
                    title: rk.i18n('OBJECT_TERMINAL'),
                    TASK_REL_NOT_EXIST: rk.i18n('TASK_REL_TERMINAL_NOT_EXIST'),
                    TASK_SYSTEM_AUTO_REL: rk.i18n('TASK_SYSTEM_AUTO_REL_TERMINAL')
                }
            };
            elem.find("#business_text").attr("placeholder",valueJson[val].placeholder+valueJson[val].title);
            elem.find("#business_text").attr("title",valueJson[val].title);
            elem.find("#business_text").val("");
            $("#business_text").autocomplete({
                source: function (request, response) {
                    var key = request.term;
                    var search_msg = function(id){
                        if (id != undefined) {
                            elem.find("#business_search_msg").html(valueJson[val].TASK_SYSTEM_AUTO_REL).show();
                            elem.find("#object_id").val(id);
                        } else {
                            elem.find("#business_search_msg").html(valueJson[val].TASK_REL_NOT_EXIST).show();
                            elem.find("#object_id").val("");
                        }
                    };
                    $.ajax({
                        url: valueJson[val].url,
                        type: 'GET',
                        data: {
                            pageNo: 1,
                            key: key.toLowerCase()
                        },
                        dataType: "json",
                        success: function (data, status) {
                            var id;
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].label == key) {
                                        id = data[i].value;
                                    }else if(data[i].name == key){
                                        id = data[i].id;
                                    }
                                }
                                search_msg(id)
                            } else {
                                search_msg(undefined)
                            }
                            response(data);
                        },
                        error: function () {
                            response([]);
                        }
                    });
                },
                select: function (event, ui) {
                    var id = ui.item.value;
                    elem.find("#object_id").val(id);
                    elem.find("#business_text").val(ui.item.label);
                    var business_search_msg = elem.find("#business_search_msg");
                    if (business_search_msg.length > 0) {
                        business_search_msg.html(valueJson[val].TASK_SYSTEM_AUTO_REL);
                    }
                    return false;
                }
            });
        },
        _typeChange: function(_suffix) {
            var me = this;
            var elem = me.element;
            var opt = me.options;
            if (typeof _suffix == "undefined") {
                _suffix = "";
            }
            $("#bussiness_type" + _suffix).selectmenu({
                appendTo: 'body'
            });
            $("#bussiness_type" + _suffix).on('selectmenuchange', function(evt, ui) {
                var val = $(this).val();

                elem.find("#object_id").val("");
                elem.find("#business_search_msg").html("").hide();
                if(val) {
                   me._business_autocomplete(val);
                }
                //if (val == 1) {
                //    $("#belong_id" + _suffix).val(1);
                //    elem.find("[act='business_spans']").hide();
                //    $("#account_span" + _suffix).show();
                //    //$("#opp_span " + _suffix + " ,#contact_span" + _suffix + ",#lead_span" + _suffix + ",#campaign_span" + _suffix).hide();
                //    $("#opp" + _suffix + ",#contact" + _suffix + ",#object_id" + _suffix + " ,#campaign" + _suffix + ",#lead" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearContact(_suffix);
                //    clearLead(_suffix);
                //    clearCampaign(_suffix)
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if (val == 2) {
                //    $("#belong_id" + _suffix).val(3);
                //    //$("#account_span" + _suffix + " ,#contact_span" + _suffix + " ,#lead_span" + _suffix + ",#campaign_span" + _suffix).hide();
                //    elem.find("[act='business_spans']").hide();
                //    $("#opp_span" + _suffix).show();
                //    $("#account" + _suffix + " ,#contact" + _suffix + " ,#object_id" + _suffix + " ,#campaign" + _suffix + " ,#lead" + _suffix).val("");
                //    clearAccount(_suffix);
                //    clearContact(_suffix);
                //    clearLead(_suffix);
                //    clearCampaign(_suffix)
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if (val == 3) {
                //    $("#belong_id" + _suffix).val(2);
                //    elem.find("[act='business_spans']").hide();
                //    $("#contact_span" + _suffix).show();
                //    //$("#account_span" + _suffix + " ,#opp_span" + _suffix + " ,#lead_span" + _suffix + ",#campaign_span" + _suffix).hide();
                //    $("#opp" + _suffix + " ,#account" + _suffix + " ,#object_id" + _suffix + " ,#campaign" + _suffix + " ,#lead" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearAccount(_suffix);
                //    clearLead(_suffix);
                //    clearCampaign(_suffix)
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if (val == 4) {
                //    $("#belong_id" + _suffix).val(11);
                //    elem.find("[act='business_spans']").hide();
                //    $("#lead_span" + _suffix).show();
                //    //$("#account_span" + _suffix + " ,#opp_span" + _suffix + " ,#contact_span" + _suffix + ",#campaign_span" + _suffix).hide();
                //    $("#opp" + _suffix + " ,#account" + _suffix + " ,#contact" + _suffix + " ,#campaign" + _suffix + " ,#object_id" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearAccount(_suffix);
                //    clearContact(_suffix);
                //    clearCampaign(_suffix)
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if (val == 5) {
                //    $("#belong_id" + _suffix).val(6);
                //    elem.find("[act='business_spans']").hide();
                //    $("#campaign_span" + _suffix).show();
                //    //$("#account_span" + _suffix + " ,#opp_span" + _suffix + " ,#contact_span" + _suffix + ",#lead_span" + _suffix).hide();
                //    $("#opp" + _suffix + " ,#account" + _suffix + " ,#contact" + _suffix + " ,#lead" + _suffix + " ,#object_id" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearAccount(_suffix);
                //    clearContact(_suffix);
                //    clearLead(_suffix);
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if (val == 6){
                //    $("#belong_id" + _suffix).val(66);
                //    elem.find("[act='business_spans']").hide();
                //    $("#campaign_span" + _suffix).show();
                //    //$("#account_span" + _suffix + " ,#opp_span" + _suffix + " ,#contact_span" + _suffix + ",#lead_span" + _suffix).hide();
                //    $("#opp" + _suffix + " ,#account" + _suffix + " ,#contact" + _suffix + " ,#lead" + _suffix + " ,#object_id" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearAccount(_suffix);
                //    clearContact(_suffix);
                //    clearLead(_suffix);
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //} else if(val == 7){
                //    $("#belong_id" + _suffix).val(67);
                //    elem.find("[act='business_spans']").hide();
                //    $("#campaign_span" + _suffix).show();
                //    //$("#account_span" + _suffix + " ,#opp_span" + _suffix + " ,#contact_span" + _suffix + ",#lead_span" + _suffix).hide();
                //    $("#opp" + _suffix + " ,#account" + _suffix + " ,#contact" + _suffix + " ,#lead" + _suffix + " ,#object_id" + _suffix).val("");
                //    clearOpp(_suffix);
                //    clearAccount(_suffix);
                //    clearContact(_suffix);
                //    clearLead(_suffix);
                //    clearAgent(_suffix);
                //    clearTerminal(_suffix);
                //}
            });

            //function clearAccount(_suffix) {
            //    $("#account_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearOpp(_suffix) {
            //    $("#opp_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearContact(_suffix) {
            //    $("#contact_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearLead(_suffix) {
            //    $("#lead_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearCampaign(_suffix) {
            //    $("#campaign_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearAgent(_suffix) {
            //    $("#agent_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}
            //
            //function clearTerminal(_suffix) {
            //    $("#terminal_search_msg" + _suffix).html("").hide();
            //    $("#object_id" + _suffix).val("");
            //}

        },
        _initDetailBottom: function() {
            var $this = this,
                $detail = this.element,
                opt = this.options;
            var entryid = opt.taskId;
            $detail.find('div.task_right_detail_inner').simpleTabs({
                active: -1,
                tabContainer: 'div.task_detail_bottom',
                tabsElement: 'ul li.jstab',
                tabsHolder: 'ul li.jstab a',
                panelsElement: '>div.bottom_tabs_content >div',
                activate: function(index, $tab, $panel, force) {
                    if ($panel.data('inited') == true && !force) {
                        return;
                    }
                    switch (index) {
                        case 1:
                            if ($this.data.files.length) {
                                $.each($this.data.files, function(_, file) {
                                    $this._appendNimei($panel, $.extend({
                                        createdByName: $this.data.users[file.createdBy].name,
                                        createAtFmt: Globalize.format(new Date(file.createdAt - 0), 'yyyy-MM-dd HH:mm')
                                    }, file));
                                });
                            }
                            
                            $panel.addClass('js-album-box').album({
                                selector: 'img.js-album'
                            });

                            $panel.on('click', '.js-file-previewable', function(evt) {
                                var $lnk = $(this),
                                    filename = $lnk.attr('filename'),
                                    swfpath = $lnk.attr('swfpath');
                                var $dialog = $('<div style="overflow: hidden;"></div>'),
                                    id = $dialog.uniqueId().attr('id');
                                $dialog.popup({
                                    width: 700,
                                    height: 600,
                                    title: rk.i18n('TASK_VIEW_FILE') + filename,
                                    resizable: true,
                                    open: function() {
                                        var flashvars = {
                                            SwfFile: escape(swfpath),
                                            Scale: 0.6,
                                            ZoomTransition: "easeOut",
                                            ZoomTime: 0.5,
                                            ZoomInterval: 0.1,
                                            FitPageOnLoad: false,
                                            FitWidthOnLoad: true,
                                            PrintEnabled: true,
                                            FullScreenAsMaxWindow: false,
                                            ProgressiveLoading: true,

                                            PrintToolsVisible: true,
                                            ViewModeToolsVisible: true,
                                            ZoomToolsVisible: true,
                                            FullScreenVisible: true,
                                            NavToolsVisible: true,
                                            CursorToolsVisible: true,
                                            SearchToolsVisible: true,
                                            localeChain: "zh_CN"
                                        };
                                        new FlexPaperViewer(SESSION.resDomain + '/static/swf/flexpager.swf', id, {
                                            config: flashvars
                                        });
                                    }
                                });
                            });
                            $panel.on('click', 'a[act="delete"]', function(evt) {
                                evt.preventDefault();
                                var $lnk = $(this);
                                $.confirm(rk.i18n('TASK_CONFIRM_DELETE_FILE'), function() {
                                    $.postJson('/json/crm_task/delete-file.action', {
                                        fileId: $lnk.attr('fileId')
                                    }).done(function(json) {
                                        if (json.status == 0) {
                                            $.msg(rk.i18n('TASK_DELETE_SUCCESS'), 1);
                                            $lnk.parents('div.detail_attachment').remove();
                                        } else {
                                            $.msg(rk.i18n('TASK_DELETE_ERROR'));
                                        }
                                    }).fail(function(def, code, message) {
                                        def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                                    });
                                });
                            });

                            var randomId = 'uploadify_queue_' + $this.uuid;
                            $panel.find('div.js-upd-queue').attr('id', randomId);

                            var $picUploadBtn = $panel.find('input.pic_attachment').uploadPic({
                                uploadify_setting: {
                                    uploader: '/json/global_uploadify/task-upload.action',
                                    buttonText: rk.i18n('TASK_UPLOAD_IMG'),
                                    buttonClass: 'pic_attachment',
                                    queueID: randomId,
                                    removeCompleted: true,
                                    removeTimeout: 0,
                                    onUploadSuccess: function(file, data, response) {
                                        var json = $.parseJSON(data);
                                        if (json.status == 0) {
                                            $this._appendImage($panel, $.extend({
                                                createdByName: SESSION.user.name,
                                                createAtFmt: Globalize.format(new Date(), 'yyyy-MM-dd HH:mm')
                                            }, json.data.file));
                                        }
                                    },
                                    onUploadStart: function(file) {
                                        $picUploadBtn.uploadify('settings', 'formData', {
                                            'pageTenantId': SESSION.tenantId,
                                            'uploadFileName': file.name,
                                            'pageUserId': SESSION.user.id,
                                            'systemItemId': entryid
                                        });
                                    }
                                }
                            });
                            var $fileUploadBtn = $panel.find('input.file_attachment').upload({
                                uploadify_setting: {
                                    uploader: '/json/global_uploadify/task-upload.action',
                                    buttonText: rk.i18n('TASK_UPLOAD_FILE'),
                                    buttonClass: 'file_attachment',
                                    queueID: randomId,
                                    removeCompleted: true,
                                    removeTimeout: 0,
                                    onUploadSuccess: function(file, data, response) {
                                        var json = $.parseJSON(data);
                                        if (json.status == 0) {
                                            $this._appendFile($panel, $.extend({
                                                createdByName: SESSION.user.name,
                                                createAtFmt: Globalize.format(new Date(), 'yyyy-MM-dd HH:mm')
                                            }, json.data.file));
                                        }
                                    },
                                    onUploadStart: function(file) {
                                        $fileUploadBtn.uploadify('settings', 'formData', {
                                            'pageTenantId': SESSION.tenantId,
                                            'uploadFileName': file.name,
                                            'pageUserId': SESSION.user.id,
                                            'systemItemId': entryid
                                        });
                                    }
                                }
                            });

                            $panel.data('inited', true);
                            break;
                        case 2:
                            $.getJSON('/json/crm_task/logs.action?taskId=' + entryid).done(function(json) {
                                if (json.status == 0) {
                                    var data = json.data,
                                        logs = data.logs;
                                    var html = $.map(logs, function(log) {
                                        var opid = log.userId,
                                            opname = data.users[opid].name,
                                            opicon = data.users[opid].icon || DEFAULTS.USER_DEFAULT_ICON,
                                            msg = '';
                                        var content = $.parseJSON(log.content);
                                        switch (log.type) {
                                            case 1: //CREATE
                                                msg = rk.i18n('TASK_TEXT_CREATE');
                                                break;
                                            case 2: //UPDATE
                                                if (log.target == 'task.label.name') {
                                                    msg = [rk.i18n('TASK_TEXT_1'),'【', content.sourceContent, '】',rk.i18n('TASK_TEXT_2'),'【', content.targetContent, '】'].join('');
                                                } else if (log.target == 'task.label.planFinishDate') {
                                                    msg = [rk.i18n('TASK_TEXT_3'),'【', moment(content.sourceContent - 0).format('YYYY-MM-DD HH:mm'), '】',rk.i18n('TASK_TEXT_2'),'【', moment(content.targetContent - 0).format('YYYY-MM-DD HH:mm'), '】'].join('');
                                                }
                                                break;
                                            case 3: //DELETE
                                                msg = rk.i18n('TASK_TEXT_DELETE_2');
                                                break;
                                            case 4: //ACCEPT
                                                msg = rk.i18n('TASK_TEXT_ACCEPT');
                                                break;
                                            case 5: //REJECT
                                                msg = [rk.i18n('TASK_TEXT_REJECT_REASON'), '“', content.reason, '”'].join('');
                                                break;
                                            case 6: //CANCEL
                                                msg = [rk.i18n('TASK_TEXT_CANCEL_OWNER'), '<a href="javascript:;" class="username">', data.users[content.sourceContent].name, '</a>'].join('');
                                                break;
                                            case 7: //TRANSFER
                                                msg = [rk.i18n('TASK_TEXT_TRANSFER'), data.entity].join('');
                                                break;
                                            case 8: //ADD
                                                msg = [rk.i18n('TASK_TEXT_ADD_MEMBER'), $.map(content.addList, function(p) {
                                                    return '<a href="javascript:;" class="username">' + data.users[p].name + '</a>';
                                                }).join('、')].join('');
                                                break;
                                            case 9: //REMOVE
                                                msg = [rk.i18n('TASK_TEXT_REMOVE_MEMBER'), $.map(content.delList, function(p) {
                                                    return '<a href="javascript:;" class="username">' + data.users[p].name + '</a>';
                                                }).join('、')].join('');
                                                break;
                                            case 10: //ASSIGN
                                                msg = [rk.i18n('TASK_TEXT_ASSIGN')+'<a href="javascript:;" class="username">' + data.users[content.targetContent].name + '</a>'].join('');
                                                break;
                                            case 11: //COMPLETE
                                                msg = rk.i18n('TASK_TEXT_FINISH');
                                                break;
                                            case 12: //RESTART
                                                msg = rk.i18n('TASK_TEXT_RESTART');
                                                break;
                                        }
                                        return ['<div class="comment_content clear"><img class="userlogo" src="', opicon, '"><div class="right_comment"><div class="comment_word"><span><a href="javascript:;" class="username">', opname, '</a></span><span>', msg, '</span></div><div class="show_tool"><a href="javascript:;" class="publish_time">', moment(log.createAt - 0).format('YYYY-MM-DD HH:mm'), '</a></div></div></div>'].join('');
                                    }).join('');
                                    $panel.find('div.show_comment').html(html);
                                    $panel.data('inited', true);
                                } else {

                                }
                            }).fail(function(def, code, message) {
                                def.status != 0 && $.msg(rk.i18n('LOAD_ERROR'));
                            });
                            break;
                    }
                }
            });
            $detail.find('div.task_right_detail_inner').simpleTabs('selectTab', 0);
            $detail.find('div.js-comments').comment({
                previewList: $this.data.comments, //预展示列表
                totalCount: $this.data.commentCount, //总条数
                canAt: 1,
                canReply: 1,
                systemId: 606,
                systemItemId: entryid,
                allusers: $this.data.users //若有previewList,需要把对应的user对象放进来
            });
        },
        _appendNimei: function($panel, file) {
            var $this = this,
                $elem = this.element,
                opt = this.options;
            if (file.fileType == 0) {
                var fileClass = '';
                var img = '';
                if (file.swf) {
                    if (file.swf == "CONVERT_FAILED") {
                        file.preview = '<div class="file_class"><img src="/static/img/preview_fail.png"></div>';
                    } else {
                        file.preview = ['<div class="file_class js-file-previewable" filename="' + file.name + '" swfpath="' + file.swf + '"><img src="', '"></div>'].join(file.img);
                    }
                } else {
                    file.preview = '<div class="file_class file_nopreview"></div>';
                }
                $panel.find('div.js-upd-queue').after(rk.templateText('<div class="detail_attachment show_file clear">{{#preview}}<div class="file_info clear"><span class="name">{{name}}</span><span class="download"><a href="/common-file-download.action?commonFileId={{id}}&tfcode={{tfcode}}">'+rk.i18n('TASK_TEXT_DOWNLOAD')+'</a><a href="javascript:;" style="margin-left:10px;" fileid="{{id}}" act="delete">'+rk.i18n('TASK_TEXT_DELETE')+'</a></span></div><div class="file_time"><span>{{createdByName}}</span><span>上传于</span><span>{{createAtFmt}}</span></div></div>', file));

            } else {
                $this._appendImage($panel, file);
            }
        },
        _appendFile: function($panel, file) {
            var $this = this,
                $elem = this.element,
                opt = this.options;
            var fileClass = '';
            var img = '';
            if (file.canPreview == 'true') {
                img = '<img src="/img/file_previewing.png">';
            } else {
                fileClass = 'file_nopreview';
            }
            $panel.find('div.js-upd-queue').after(rk.templateText('<div class="detail_attachment show_file clear"><div class="file_class ' + fileClass + '">' + img + '</div><div class="file_info clear"><span class="name">{{name}}</span><span class="download"><a href="/common-file-download.action?commonFileId={{id}}&tfcode={{tfcode}}">'+rk.i18n('TASK_TEXT_DOWNLOAD')+'</a><a href="javascript:;" style="margin-left:10px;" fileid="{{id}}" act="delete">'+rk.i18n('TASK_TEXT_DELETE')+'</a></span></div><div class="file_time"><span>{{createdByName}}</span><span>上传于</span><span>{{createAtFmt}}</span></div></div>', file));
        },
        _appendImage: function($panel, file) {
            var $this = this,
                $elem = this.element,
                opt = this.options;
            $panel.find('div.js-upd-queue').after(rk.templateText('<div class="detail_attachment show_file clear"><div class="file_class"><img href="{{pic}}" lurl="{{url}}" surl="{{url}}" src="{{pic}}" class="js-album"></div><div class="file_info clear"><span class="name">{{name}}</span><span class="download"><a href="/common-file-download.action?commonFileId={{id}}&tfcode={{tfcode}}">'+rk.i18n('TASK_TEXT_DOWNLOAD')+'</a><a href="javascript:;" style="margin-left:10px;" fileid="{{id}}" act="delete">'+rk.i18n('TASK_TEXT_DELETE')+'</a></span></div><div class="file_time"><span>{{createdByName}}</span><span>上传于</span><span>{{createAtFmt}}</span></div></div>', file));
        }


            });
    return {
        init: function(rkContent, id) {
            rkContent.taskContentCtrl({
                taskId: id
            });
        }
    }
});
